#ifndef QSINGLETON_H
#define QSINGLETON_H

#include <QHash>
#include <QMetaObject>
#include <QPointer>

/** 
 Singletonize your QObject class, When inheriting this template, you self made your class singletonizable.
 We can call like this YourClass::instance() 
*/
template <class T>
class QSingleton
{
protected:
	QSingleton() {};
	virtual ~QSingleton() { };

public:

	/** Return an unique instance of the class */
	static T* instance()
	{
//		static QPointer<T> mInstance;//(new T);
 		if(!mInstance)
 			mInstance = new T;
 		return mInstance;
	}

	/** Clear the instance if instance is available */
	static void clearInstance() 
	{
		delete mInstance;// instance();
// 		mInstance = 0;
	}

private:
	static QPointer<T> mInstance;
};

template <class T>
QPointer<T> QSingleton<T>::mInstance = 0;

#endif